package com.tanhua.manage.controller;

import com.tanhua.manage.service.FreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("management/manage/users")
public class FreezeController {

    private FreezeService freezeService;
    @Autowired
    private void setFreezeService(FreezeService freezeService){
        this.freezeService = freezeService;
    }

    /**
     * 冻结用户
     *
     * @param param
     * @return
     */
    @PostMapping("freeze")
    public ResponseEntity<Map<String, String>> userFreeze(@RequestBody Map<String, String> param) {
        try {
            //调用业务层处理
            Map<String, String> message = freezeService.userFreeze(param);
            return ResponseEntity.status(200).body(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 解冻用户
     *
     * @param param
     * @return
     */
    @PostMapping("unfreeze")
    public ResponseEntity<Map<String, String>> userUnfreeze(@RequestBody Map<String, String> param) {

        try {
            Map<String, String> message = freezeService.userUnfreeze(param);
            return ResponseEntity.status(200).body(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }



}
